package br.com.bacabeleireiros.sysbeleza.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ForeignKey;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

@Entity
@Table(name = "agenda")
public class Agenda implements Serializable {

	private static final long serialVersionUID = 1L;
	private Long idAgenda;
	private Cliente cliente;
	private Funcionario funcionario;
	private Servico servico;
	private Date dataInicio;
	private Date datafinal;
	private double valor;
	private String observacao;
	private Horario horario;
	@Transient
	private Long idHoraFinal;
	private Boolean isEncaixe;

	public Agenda() {
		cliente = new Cliente();
		funcionario = new Funcionario();
		servico = new Servico();
		horario = new Horario();
	}

	// gets e sets

	@Id
	@SequenceGenerator(name = "seqAgenda", sequenceName = "seq_agenda", allocationSize = 1)
	@GeneratedValue(generator = "seqAgenda", strategy = GenerationType.SEQUENCE)
	@Column(name = "id_agenda")
	public Long getIdAgenda() {
		return idAgenda;
	}

	public void setIdAgenda(Long idAgenda) {
		this.idAgenda = idAgenda;
	}

	@ManyToOne
	@JoinColumn(name = "id_cliente", foreignKey = @ForeignKey(name = "fk_agenda_ciente"))
	public Cliente getCliente() {
		return cliente;
	}

	public void setCliente(Cliente cliente) {
		this.cliente = cliente;
	}

	@ManyToOne
	@JoinColumn(name = "id_funcionario", foreignKey = @ForeignKey(name = "fk_agenda_funcionario"))
	public Funcionario getFuncionario() {
		return funcionario;
	}

	public void setFuncionario(Funcionario funcionario) {
		this.funcionario = funcionario;
	}

	@ManyToOne
	@JoinColumn(name = "id_servico", foreignKey = @ForeignKey(name = "fk_agenda_servico"))
	public Servico getServico() {
		return servico;
	}

	public void setServico(Servico servico) {
		this.servico = servico;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "data_inicio")
	public Date getDataInicio() {
		return dataInicio;
	}

	public void setDataInicio(Date dataInicio) {
		this.dataInicio = dataInicio;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "data_final")
	public Date getDatafinal() {
		return datafinal;
	}

	public void setDatafinal(Date datafinal) {
		this.datafinal = datafinal;
	}

	@Column(name = "valor")
	public double getValor() {
		return valor;
	}

	public void setValor(double valor) {
		this.valor = valor;
	}
	
	@Column(name = "observacao")
	public String getObservacao() {
		return observacao;
	}

	public void setObservacao(String observacao) {
		this.observacao = observacao;
	}
	
	
	@ManyToOne
	@JoinColumn(name = "id_horario", foreignKey = @ForeignKey(name = "fk_agenda_horario"))
	public Horario getHorario() {
		return horario;
	}

	public void setHorario(Horario horario) {
		this.horario = horario;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((idAgenda == null) ? 0 : idAgenda.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Agenda other = (Agenda) obj;
		if (idAgenda == null) {
			if (other.idAgenda != null)
				return false;
		} else if (!idAgenda.equals(other.idAgenda))
			return false;
		return true;
	}

	public Long getIdHoraFinal() {
		return idHoraFinal;
	}

	public void setIdHoraFinal(Long idHoraFinal) {
		this.idHoraFinal = idHoraFinal;
	}

	@Column(name = "is_encaixe")
	public Boolean getIsEncaixe() {
		return isEncaixe;
	}

	public void setIsEncaixe(Boolean isEncaixe) {
		this.isEncaixe = isEncaixe;
	}

}